#!/bin/python
#-*- coding:utf-8 -*-
# Filename:    main.py
# Revision:    1.0
# Date:        2012-06-14
# Author:      simonzhang
# web:         www.simonzhang.net
# Email:       simon-zzm@163.com
### END INIT INFO
import os
import sys
import tornado.ioloop
import tornado.locale
import tornado.web
import time
from dbmodel import *
from interface import *


class ProjectTreeHandler(BaseHandler):
    @tornado.web.authenticated
    def get(self):
        _get_user = self.check_user()
        _domain, _title = if_get_domain_title()
        _get_user_left_menu = if_get_user_left_menu(_get_user)
        try:
            _get_project_name = self.get_argument("p")
        except:
            _get_project_name = u"选择项目"
        if u"%s" % _get_project_name == u"选择项目":
            self.write(u"别瞎操作")
            return
        _html_context = ""
        if os.path.exists("project/%s" % _get_project_name) == True:
            find_walk=os.walk("project/%s" % _get_project_name)
            for path,dirs,files in find_walk:
                for file in files:
                    _html_context += "%s/%s<br>" % (path, file)
        else:
            self.write(u"没有完整代码目录")
            return
        self.write(_html_context)


class GetVerServerInfoHandler(BaseHandler):
    @tornado.web.authenticated
    def get(self):
        _get_user = self.check_user()
        _domain, _title = if_get_domain_title()
        _get_user_left_menu = if_get_user_left_menu(_get_user)
        try:
            _get_project_name = self.get_argument("p")
        except:
            _get_project_name = u"选择项目"
        if u"%s" % _get_project_name == u"选择项目":
            self.write(u"别瞎操作")
            return
        _get_info = odb_version_server_info(_get_project_name)
        ver_server=""
        if _get_info["svn_url"] != None:
            ver_server += "<option>svn</option>\n"
        if _get_info["git_url"] != None:
             ver_server += "<option>git</option>"
        if len(ver_server) != 0:
           self.write(ver_server)
        else:
           self.write("<option>没有版本服务器</option>")

class MakePackageHandler(BaseHandler):
    @tornado.web.authenticated
    def get(self):
        _get_user = self.check_user()
        _domain, _title = if_get_domain_title()
        _get_user_left_menu = if_get_user_left_menu(_get_user)
        _get_user_manage_project = if_get_user_project(_get_user)
        self.render("templates/make_package.html", domain=_domain, \
                                                   title=_title, \
                                                   username = _get_user, \
                                                   items=_get_user_left_menu, \
                                                   pros=_get_user_manage_project)
    def post(self):
        get_now_unix_time = int(time.time())
        print get_now_unix_time

